// head = [3,2,0,-4], pos = 1
/**
 * 判断是否有环
 * 方法一：set
 * 方法二：双指针
 *  */ 

/**
 * 反转链表
 * 方法一：递归
 * 方法二: 遍历
 * */
var reverseList = function(head) {
  if(head==null || head.next == null){
      return head
  }
  var list = new ListNode()
  list = reverseList(head.next)
  var p1 = head.next
  p1.next = head
  head.next = null
  return list
};
var reverseList = function(head) {
  let currPoint = head; // 当前指针节点
  let nextPoint = null; // 后一指针节点
  let list = head; // 一直指向头指针
  if(currPoint == null) return null;
  while(currPoint.next!==null){
      nextPoint = currPoint.next; // nextPoint为当前指针节点的下一节点
      currPoint.next = nextPoint.next // 当前指针节点后移
      nextPoint.next = list; // 当前指针节点的后一节点移动到头指针节点
      list = nextPoint; // list始终指向头节点
  }
  return list;
};